<template>
  <div id="boat-list">
    <div id="boat_filter" class="boat_filter" v-show="this.showSearchFilter">
      <div class="book-trip">
          <div class="travel-booking-panel">
            <row>
              <i-col span="8">
                <div class="search-field-group">
                  <Cascader :data="locationList" v-model="searchCriteria.location" filterable="true" size="large" placeholder="目的地"></Cascader>
                </div>
              </i-col>
              <i-col span="8">
                <div class="search-field-group">
                  <Date-picker type="datetimerange" placeholder="预订日期" format="yyyy-MM-dd" style="width:100%" v-model="searchCriteria.checkInDate"></Date-picker>
                </div>
              </i-col>
              <i-col span="8">
                <div class="search-field-group">
                  <label >价格范围（每小时价）:&nbsp;{{searchCriteria.price[0]}}-{{searchCriteria.price[1]}}元</label>
                  <Slider v-model="searchCriteria.price" :step="100" :min="0" :max="10000" range show-stops style="padding-left:15px;"></Slider>
                </div>

              </i-col>
            </row>
          </div>
          <div class="travel-booking-panel">
              <row>
                <i-col span="8">
                  <div class="search-field-group">
                    <label >载客数:&nbsp;{{searchCriteria.capacity[0]}}-{{searchCriteria.capacity[1]}}人</label>
                    <Slider v-model="searchCriteria.capacity" :step="1" :min="0" :max="25" range show-stops style="padding-left:15px;"></Slider>
                  </div>
                </i-col>
                <i-col span="8">
                  <div class="search-field-group">
                    <label >客舱数:&nbsp;{{searchCriteria.cabs[0]}}-{{searchCriteria.cabs[1]}}</label>
                    <Slider v-model="searchCriteria.cabs" :step="1" :min="0" :max="10" range show-stops style=" padding-left:15px;"></Slider>
                  </div>
                </i-col>
                <i-col span="8">
                  <div class="search-field-group">
                    <label >床位数:&nbsp;{{searchCriteria.beds[0]}}-{{searchCriteria.beds[1]}}</label>
                    <Slider v-model="searchCriteria.beds" :step="1" :min="0" :max="10" range show-stops style="padding-left:15px;"></Slider>
                  </div>
                </i-col>
              </row>
          </div>
          <div class="travel-booking-panel">
              <row>
                <i-col span="8">
                  <div class="search-field-group">
                    <Select v-model="searchCriteria.builder" clearable placeholder="船艇品牌（建造商）">
                      <Option v-for="item in brandList" :value="item.value" :key="item">{{ item.label }}</Option>
                    </Select>
                  </div>
                </i-col>
                <i-col span="8">
                  <div class="search-field-group">
                    <Select v-model="searchCriteria.boatType" clearable placeholder="船型">
                      <Option v-for="item in boatTypeList" :value="item.value" :key="item">{{ item.label }}</Option>
                    </Select>
                  </div>
                </i-col>
                <i-col span="8">
                  <div class="search-field-group">
                    <Select v-model="searchCriteria.meal" clearable placeholder="餐饮服务" style="width: 60%">
                      <Option value="1">有</Option>
                      <Option value="0">无</Option>
                    </Select>
                    <button type="submit" class="button-submit" @click="goSearch">
                      <span class="button-title-large">搜索</span>
                      <i class="fa fa-angle-right" aria-hidden="true" style="float:right; padding-top:5px"></i>
                    </button>
                  </div>
                </i-col>
              </row>
          </div>
      </div>
    </div>
    <div class="content-list">
      <div class="sort-bar">
        <div class="col-half-left">
          <div class="form-inline">
            <div class="form-group">
              <label >排序:</label>
              <Select v-model="sortBy" style="width:200px">
                <Option v-for="item in sortList" :value="item.value" :key="item">{{ item.label }}</Option>
              </Select>
            </div>
          </div>
        </div>
        <div class="col-half-right">
          <span class="page-count">共{{page.totalCount}}个记录 显示{{this.firstOfCurrPage}}-{{this.lastOfCurrPage}}条</span>	</div>
        <div class="clearfix"></div>
      </div>

      <ol class="results">
        <li class="b" v-for="item in page.list">
          <div class="boat">
            <row>
              <i-col span="6" >
                <div class="image" >
                  <img :src="item.mainImg" style="width:100%; height:100%"/>
                  <ul class="flag">
                  <span class="promo">
                    <span class="fa fa-tag"></span> {{item.discount}}
                  </span>
                  </ul>
                </div>
              </i-col>
              <i-col span="12">
                <div class="info">
                  <router-link to="boat_detail" >
                    <b>{{item.boatName}}</b>
                    <span v-for="locItem in item.locations">{{locItem}} /</span>
                  </router-link>
                  <div class="specs">
                    <div class="m" data-toggle="tooltip" data-placement="top" data-delay="500" title="" data-original-title="Capacity">
                      <span class="cap">Capacity</span> {{item.capacity}}人
                    </div>
                    <div class="m" data-toggle="tooltip" data-placement="top" data-delay="500" title="" data-original-title="Cabins">
                      <span class="cab">Cabins</span> {{item.cab}}客舱
                    </div>
                    <div class="m" data-toggle="tooltip" data-placement="top" data-delay="500" title="" data-original-title="Berths">
                      <span class="ber">Berths</span>{{item.beds}}床位</div>
                    <div class="m" data-toggle="tooltip" data-placement="top" data-delay="500" title="" data-original-title="Engine">
                      <span class="mot">Engine</span> 2x30hp</div>
                    <div class="m" data-toggle="tooltip" data-placement="top" data-delay="500" title="" data-original-title="Draught">
                      <span class="dra">Draught</span>{{item.draft}}{{item.unit}}</div>
                    <div class="m" data-toggle="tooltip" data-placement="top" data-delay="500" title="" data-original-title="Size">
                      <span class="len">Size</span> {{item.boatSize}}{{item.unit}}</div>
                  </div>
                  <div class="pluses">
                    <div class="item">
                      <Rate show-text allow-half v-model="starRate">
                        <span style="color: #2d8cf0; font-size: 12px">13 reviews</span>
                      </Rate>
                    </div>
                    <div class="item inc">
                      <span class="fa fa-check"></span>
                      <span class="font-size=12px" v-for="equipItem in item.equips" >
                        {{equipItem}}/
                      </span>
                    </div>
                  </div>
                </div>
              </i-col>
              <i-col span="6">
                <div class="price text-center">
                  <i class="favorite fa fa-heart-o" onclick=""></i>
                  <!--span class="op">结算价 ￥{{item.priceList[0].settlePrice}}</span--><b class="p">￥{{item.priceList[0].price}}</b>
                  <span class="period">自 {{formatIntDate(item.priceList[0].from,'begin')}} 到 {{formatIntDate(item.priceList[0].to, 'end')}}</span>

                  <a class="view-detail" @click="viewBoatDetail(item.id)">查看详情&nbsp;</a>

                </div>
              </i-col>
            </row>
          </div>
        </li>
      </ol>
      <div class="bottom_pagination text-right text_center_xs">
        <ul class="pager">
          <li class="previous"><a @click="goPrevious">
            <span class="fa fa-angle-left" aria-hidden="true"></span> Previous</a>
          </li>
          <li class="next"><a @click="goNext">Next <span class="fa fa-angle-right" aria-hidden="true"></span></a>
          </li>
        </ul>
      </div>
  </div>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  export default {
    components: {},
    name: 'boat-list',
    props: ['from'],
    data () {
      return {
        page: {
          totalCount: 0,
          pageSize: 0,
          totalPage: 0,
          currPage: 0,
          list: []
        },
        searchCriteria: {
          location: '',
          checkInDate: '',
          price: [],
          capacity: [],
          cabs: [],
          beds: [],
          builder: '',
          boatType: '',
          ownership: '',
          meal: ''
        },
        locationList: [],
        boatTypeList: [
          {label: '帆船', value: 'SAILBOAT'},
          {label: '机动游艇', value: 'MOTORBOAT'},
          {label: '双体帆船', value: 'CATAMARAN'},
          {label: '鱼钓船', value: 'FISHINGBOAT'},
          {label: '橡皮艇', value: 'RIB'},
          {label: '摩托艇', value: 'JETSKI'},
          {label: '房艇', value: 'HOUSEBOAT'},
          {label: '皮划艇', value: 'KAYAK'},
          {label: '培训', value: 'LESSONS'},
          {label: '水上运动', value: 'WATERSPORTS'},
          {label: '观光艇', value: 'TOURS'}
        ],
        ownershipList: [
          {
            value: 'PERSONAL',
            label: '私人'
          },
          {
            value: 'FIRM',
            label: '公司'
          }
        ],
        brandList: [
          {
            value: 'Lagoon',
            label: 'Lagoon'
          },
          {
            value: 'Bavaria',
            label: 'Bavaria'
          },
          {
            value: 'Azimut',
            label: 'Azimut'
          }
        ],
        sortList: [
          {
            value: 'priceLowToHigh',
            label: '价格从低到高'
          },
          {
            value: 'priceHighToLow',
            label: '价格从高到低'
          },
          {
            value: 'popularity',
            label: '热度'
          },
          {
            value: 'CapacityLowToHigh',
            label: '载客数从低到高'
          },
          {
            value: 'CapacityHighToLow',
            label: '载客数从高到低'
          }
        ],
        sortBy: '',
        starRate: 3.5
      }
    },
    computed: {
      ...mapGetters(['showSearchFilter']),
      firstOfCurrPage () {
        return (this.page.currPage - 1) * this.page.pageSize + 1
      },
      lastOfCurrPage () {
        return this.page.currPage * this.page.pageSize
      }
    },
    methods: {
      viewBoatDetail (boatId) {
        if (this.from === 'prod') {
          this.$router.push({name: 'viewBoat', params: {boatId: boatId}})
        }
        if (this.from === 'search') {
          this.$router.push({name: 'viewSearchBoat', params: {boatId: boatId}})
        }
      },
      queryBoats () {
        var qParam = '&page=' + (this.page.currPage)
        if (this.searchCriteria.location !== null && this.searchCriteria.location.length > 0) {
          qParam += '&location=' + this.searchCriteria.location
        }
        if (this.searchCriteria.builder !== null && this.searchCriteria.builder.length > 0) {
          qParam += '&builder=' + this.searchCriteria.builder
        }
        if (this.searchCriteria.boatType !== null && this.searchCriteria.boatType.length > 0) {
          qParam += '&boatType=' + this.searchCriteria.boatType
        }
//        if (this.searchCriteria.ownership !== null && this.searchCriteria.ownership.length > 0) {
//          qParam += '&ownership=' + this.searchCriteria.ownership
//        }
        if (this.searchCriteria.capacity !== null && this.searchCriteria.capacity.length > 0) {
          if (this.searchCriteria.capacity[0] !== null) {
            qParam += '&capacityFrom=' + this.searchCriteria.capacity[0]
          }
          if (this.searchCriteria.capacity[1] !== null) {
            qParam += '&capacityTo=' + this.searchCriteria.capacity[1]
          }
        }
        if (this.searchCriteria.cabs !== null && this.searchCriteria.cabs.length > 0) {
          if (this.searchCriteria.cabs[0] !== null) {
            qParam += '&cabsFrom=' + this.searchCriteria.cabs[0]
          }
          if (this.searchCriteria.cabs[1] !== null) {
            qParam += '&cabsTo=' + this.searchCriteria.cabs[1]
          }
        }
        if (this.searchCriteria.beds !== null && this.searchCriteria.beds.length > 0) {
          if (this.searchCriteria.beds[0] !== null) {
            qParam += '&bedsFrom=' + this.searchCriteria.beds[0]
          }
          if (this.searchCriteria.beds[1] !== null) {
            qParam += '&bedsTo=' + this.searchCriteria.beds[1]
          }
        }
        if (this.searchCriteria.price !== null && this.searchCriteria.price.length > 0) {
          if (this.searchCriteria.price[0] !== null) {
            qParam += '&priceFrom=' + this.searchCriteria.price[0]
          }
          if (this.searchCriteria.price[1] !== null) {
            qParam += '&priceTo=' + this.searchCriteria.price[1]
          }
        }
        this.$http.get('api/boat/list?limit=10' + qParam).then((response) => {
          this.$data.page = response.data.obj
        })
      },
      goSearch () {
        this.page.currPage = 0
        this.queryBoats()
      },
      goPrevious () {
        if (this.page.currPage === 1) {
          this.$Message.warning('已经到达首页')
          return
        } else {
          this.page.currPage --
          this.queryBoats()
        }
      },
      goNext () {
        if (this.page.currPage === this.page.totalPage) {
          this.$Message.warning('已经到达末页')
          return
        } else {
          this.page.currPage ++
          this.queryBoats()
        }
      },
      formatIntDate (intDate, ind) {
        if (intDate === null || intDate === 0) {
          return ''
        }
        var fTime = new Date()
        fTime.setTime(intDate * 1000)
        var year, month, day
        if (isNaN(fTime.getFullYear())) {
          year = new Date().getFullYear().toString()
        } else {
          year = fTime.getFullYear().toString()
        }

        if (isNaN(fTime.getMonth())) {
          if (ind === 'begin') {
            month = 1
          } else if (ind === 'end') {
            month = 12
          }
        } else {
          month = fTime.getMonth().toString()
        }

        if (isNaN(fTime.getDate())) {
          if (ind === 'begin') {
            day = 1
          } else if (ind === 'end') {
            day = 31
          }
        } else {
          day = fTime.getDate().toString()
        }
        return year + '-' + month + '-' + day
      }
    },
    mounted () {
      this.$http.get('api/boat/list?offset=1&limit=10').then((response) => {
        this.$data.page.currPage = 1
        this.$data.page = response.data.obj
      })
      this.$http.get('api/region/list').then((response) => {
        this.locationList = response.data.obj
      })
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .book-trip {
    margin: 0 auto;
    padding: 1.125rem 0 2rem;
    width: 90%;
  }
  .travel-booking-panel {
    margin: 10px 10px 10px 10px;
  }
  .search-field-group {
    margin: 0 5px 0 5px;
  }
  .search-field-group label {
    display: inline-block;
    margin-bottom: -2px;
    font-size: 12px;
    line-height: 12px;
    max-width: 100%;
    color: #bbbec4;
  }

  .book-trip .button-submit {
    float: right;
    text-align: left;
    width: 35%;
    height: 50px;
    margin: 0 0 0 3px;
    max-height: 32px;
    padding: 0 1em;
    position: relative;
    background: #ff5a5f;
    border: 1px solid transparent;
    border-radius: 2px;
    box-shadow: 0 1px 0 0 #c6c2c1;
    color: #fff;
    overflow: visible;
  }

  .banner-inner img {
    min-height: 251px;
    min-width: 1400px;
    width: 100%;
    vertical-align: middle;
    border: 0 none;
  }

  .content-list {
    width: 100%;
    float: right;
    min-height: 1px;
    padding-left: 5px;
    padding-right: 5px;
    position: relative;
  }

  .sort-bar {
    background: #ebedec none repeat scroll 0 0;
    margin-top: 10px;
    padding: 5px 0;
    heidht: 40px;
  }

  .col-half-left {
    width: 50%;
    float: left;
    min-height: 1px;
    padding-left: 15px;
    padding-right: 15px;
    position: relative;
    background: #ebedec;
    height: 40px;
  }

  .col-half-right {
    width: 50%;
    float: right;
    min-height: 1px;
    padding-left: 15px;
    padding-right: 15px;
    position: relative;
    background: #ebedec;
    height: 40px;
  }

  .form-inline .form-group {
    display: inline-block;
    margin-bottom: 0;
    vertical-align: middle;
  }

  .sort-bar label {
    display: inline-block;
    font-weight: bold;
    margin-bottom: 5px;
    max-width: 100%;
  }

  .form-inline .search-sort-select {
    display: inline-block;
    font-weight: bold;
    margin-bottom: 5px;
    max-width: 100%;
  }

  .text-right {
    text-align: right;
    padding-left: 15px;
    padding-right: 15px;
    position: relative;
  }

  .page-count {
    display: block;
    padding: 5px 0 0;
  }

  .content-list .results {
    margin-top: 45px;
    overflow:hidden;
    padding: 0;
  }

  .results li::after {
    background: #fff none repeat scroll 0 0;
    border-bottom: 1px solid #c5c5c5;
    clear: both;
    content: "";
    display: block;
    float: none;
    height: 1px;
    margin-bottom: 12px;
    margin-top: 12px;
  }
  .results li {
    list-style: outside none none;
  }

  .results .boat {
    display: table;
    width: 100%;
    height: 150px;
    background: #ebedec none repeat scroll 0 0;;
    background-size: cover;
  }

  .results .boat .image {
    display: block;
    float: none;
    vertical-align: top;
    background-position: 50% 50%;
    background-size: cover;
    cursor: pointer;
    margin: 0;
    min-height: 170px;
    height: 170px;
    padding: 0;
    overflow: hidden;
  }
  .results .boat .image .flag {
    font-size: 14px;
    font-weight: 500;
    list-style: outside none none;
    margin-top: 5px;
    padding: 0;
    position: absolute;
    top:0;
    cursor: pointer;
  }

  .results .boat .image .flag .promo {
    background: #ff3350 none repeat scroll 0 0;
    color: #fff;
    margin-bottom: 2px;
    padding: 2px 4px;
    font-size: 14px;
    font-weight: 500;
  }

  .results .boat .info {
    background: #fff none repeat scroll 0 0;
    overflow:auto;
    height:170px;
    padding-left:10px;
  }

  .results .boat .info .model b {
    display: block;
    font-size: 16px;
  }

  .results .boat .info .model span {
    color: #808080;
    display: block;
    font-size: 14px;
  }

  .results .boat .info .specs::after {
    clear: both;
    content: "";
    display: block;
    height: 0;
  }

  .results .boat .info .specs {
    display: block;
    margin: 0 0 10px;
    padding: 0;
  }

  .results .boat .info {
    float: none;
    vertical-align: top;
  }

  .results .boat .info .specs .m {
    background: #fff none repeat scroll 0 0;
    border: 1px solid #c5c5c5;
    display: block;
    float: left;
    font-size: 10px;
    margin-bottom: 5px;
    margin-right: 5px;
    overflow: hidden;
    padding: 1px 2px 2px;
    text-align: center;
    white-space: nowrap;
    width: 48px;
  }
  .results .boat .info .specs .m span {
    background: rgba(0, 0, 0, 0) url("../../assets/legend2.png") no-repeat scroll 0 0 / 285px 28px;
    border-bottom: 1px solid #c5c5c5;
    display: block;
    height: 32px;
    margin: 2px;
    overflow: hidden;
    text-indent: 50px;
    width: 40px;
  }

  .results .boat .info .specs .m .cab {
    background-position: -123px 0;
  }

  .results .boat .info .specs .m .ber {
    background-position: -41px 0;
  }

  .results .boat .info .specs .m .mot {
    background-position: -82px 0;
  }

  .results .boat .info .specs .m .dra {
    background-position: -163px 0;
  }

  .results .boat .info .specs .m .len {
    background-position: -203px 0;
  }

  .results .boat .info .pluses::after {
    clear: both;
    content: "";
    display: block;
    height: 0;
    overflow: hidden;
    width: 0;
  }

  .results .boat .info .pluses .item:first-child {
    border-left: 0 none;
    padding-left: 0;
  }

  .results .boat .info .pluses .item {
    border-left: 1px solid #eaeaea;
    color: #424242;
    float: left;
    font-size: 10px;
    font-weight: 300;
    height: 24px;
    letter-spacing: -0.5px;
    line-height: 20px;
    margin-bottom: 6px;
    padding: 0 10px;
  }
  .results .boat .info .pluses .item span{
    font-size: 10px;
  }
  .results .boat .price .view-detail {
    font-size: 12px;
    font-weight: 500;
    hyphens: none;
    margin: 6px 0;
    overflow-wrap: normal;
    text-transform: uppercase;
    white-space: normal;
    word-break: normal;
    text-align: center;
    -moz-user-select: none;
    border-radius: 0;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
    line-height: 1.42857;
    padding: 6px 12px;
    touch-action: manipulation;
    vertical-align: middle;
    padding: 6px 12px;
    background: #24BFB4;
    border-color: #24BFB4;
    color: #fff;
  }


  .text-center {
    text-align: center;
  }

  .results .boat .price .op {
    color: #808080;
    display: block;
    font-size: 12px;
    font-weight: normal;
    padding: 0;
    text-decoration: line-through;
  }

  .results .boat .price .p {
    color: #ff3350;
    display: block;
    font-size: 22px;
  }

  .results .boat .price {
    background: #eaeaea none repeat scroll 0 0;
    min-height: 170px;
    padding: 25px 0;
  }

  .results .boat .price {
    float: none;
    vertical-align: top;
  }

  .results .boat .price .favorite {
    color: #808080;
    cursor: pointer;
    float: right;
    font-size: 18px;
    margin: -20px 5px 0 0;
    opacity: 0.5;
  }

  .results .boat .price .period {
    color: #808080;
    display: block;
    text-align: center;
  }

  .bottom_pagination {
    background: #ebedec none repeat scroll 0 0;
    margin-bottom: 20px;
    padding: 10px;
    height: 50px;
  }

  .pager {
    list-style: outside none none;
    padding-left: 0;
    text-align: center;
  }

  .pager li {
    display: inline;
    list-style: outside none none;
  }

  .pager .previous > a, .pager .previous > span {
    list-style: outside none none;
    float: left;
  }

  .pager li > a, .pager li > span {
    background-color: #fff;
    border: 1px solid #ddd;
    display: inline-block;
    padding: 5px 14px;
    font-size: 14px;
  }

  .pager .next > a, .pager .next > span {
    list-style: outside none none;
    float: right;
  }
</style>
